package com.hyb.algorithm.data.struct.list;

/**
 * @author: ybhu
 * @create: 2021/09/19 22:57
 * 206. 反转链表
 * https://leetcode-cn.com/problems/reverse-linked-list/
 *
 * 视频教程
 * https://www.bilibili.com/video/BV1KZ4y157Up?from=search&seid=10662657836028840236&spm_id_from=333.337.0.0
 *
 */
public class ReverseLinkedList {

    public ListNode reverseList(ListNode head) {

        ListNode prev=null;
        ListNode cur=head;
        while(cur!=null){
            //临时记录 下一个节点
            ListNode temp=cur.next;
            cur.next=prev;
            prev=cur;
            cur=temp;
        }

        return prev;
    }
}
